﻿namespace Example
{
    using Cavity;

    using NodaTime;

    using Xunit;

    public sealed class NodaTimeInstantFacts
    {
        [Fact]
        [Comment("Epoch is 1970 UTC; an instant isn't really 'in' a time zone or calendar, but it is convenient to consider UTC in the ISO-8601 calendar.")]
        public void ctor_long()
        {
            const string expected = "1970-01-01T00:00:01Z";
            var actual = new Instant(10000000).ToString(); // 10 million ticks = 1 second...

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void op_FromUtc()
        {
            var instant = Instant.FromUtc(2010, 6, 9, 14, 15, 0);

            Assert.Equal(12760929000000000, instant.Ticks);
            Assert.Equal("2010-06-09T14:15:00Z", instant.ToString());
        }

        [Fact]
        public void op_Subtraction_Instant_Instant()
        {
            var begin = Instant.FromUtc(2008, 4, 3, 10, 35, 0);
            var end = Instant.FromUtc(2008, 4, 3, 10, 35, 1);

            var duration = end - begin;

            Assert.Equal(10000000, duration.Ticks);
        }
    }
}